import django.http as h
import django.shortcuts as sc
import django.template as t

import ourcity.elections.models as em
import ourcity.reps.models as rm 

def index(request, slug):
    context = t.RequestContext(request)
    election = sc.get_object_or_404(em.Election, slug=slug)
    context['election'] = election
    reps = election.candidates.all()
    context['reps_by_name'] = reps.order_by('last_name', 'first_name')
    context['candidates_table'] = True
    template = t.loader.get_template('elections/index.html')
    return h.HttpResponse(template.render(context))
